package com.rtx.wms.std.adjustment.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.rtx.wms.std.adjustment.bean.Adjustment;
import com.rtx.wms.std.adjustment.bean.Adjustmentdetail;
import com.rtx.wms.std.adjustment.mapper.AdjustmentMapper;
import com.rtx.wms.std.adjustment.mapper.AdjustmentdetailMapper;
import com.rtx.wms.std.adjustment.service.AdjustmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.rtx.api.annotation.DataSourceAnnotation;

@Service
public class AdjustmentServiceImpl implements AdjustmentService {

	@Autowired
	private AdjustmentMapper adjustmentMapper;

	@Autowired
	private AdjustmentdetailMapper adjustmentdetailMapper;
	
	@DataSourceAnnotation
	@Override
	public List<Adjustment> selectAdjustmentByWrapper(String whseid, Wrapper<Adjustment> wrapper) {
		List<Adjustment> adjustmentList = adjustmentMapper.selectList(wrapper);
		for(Adjustment adjustment : adjustmentList){
			LambdaQueryWrapper<Adjustmentdetail> queryWrapper = Wrappers.lambdaQuery();
			queryWrapper.eq(Adjustmentdetail::getAdjustmentkey,adjustment.getAdjustmentkey());
			adjustment.setDetails(adjustmentdetailMapper.selectList(queryWrapper));
		}
		return adjustmentList;
	}

	@DataSourceAnnotation
	@Override
	public void updateByWrapper(String whseid, LambdaUpdateWrapper<Adjustment> wrapper) {
		adjustmentMapper.update(null,wrapper);
	}
	
}
